
inquireListForM = function(){
Ext.define('inquireModel',{
	extend:'Ext.data.Model',
	fields:[
	        	{name:'inquireCode',type:'String'},
	        	{name:'inquireTitle',type:'String'},
	        	{name:'inquireA',type:'String'},
	        	{name:'inquireB',type:'string'},
	        	{name:'inquireC',type:'string'},
		        {name:'inquireD',type:'string'}
		       ]
});

var inquirestore = Ext.create('Ext.data.Store',{
	model:inquireModel,
	autoLoad:true,
	proxy:{
		type:'ajax',
		url:'selectInquireAction.action',
		reader:{
			type:'json',
			root:'inquireList'
		},
		extraParams:{
    		//publicCode:'professional'
    	}
	}
});
var checkBox = Ext.create('Ext.selection.CheckboxModel');
var grid = Ext.create('Ext.grid.GridPanel',{
	store:inquirestore,	
	columnLines:true,
	selModel:checkBox,
	disableSelection:false,
	loadMask:true,
	columns:[
	         {text:'问题编号',width:150,dataIndex:'inquireCode',sortable:true,hidden:true},
	         {text:'问题',width:250,dataIndex:'inquireTitle'},
	         {text:'答案A(85~100分)',width:150,dataIndex:'inquireA'},
	         {text:'答案B(70~85分)',width:150,dataIndex:'inquireB'},
	         {text:"答案C(60~70分)",width:150,dataIndex:'inquireC'},
	         {text:"答案D(<60分)",width:150,dataIndex:'inquireD'}
	         ],
	autoHeight:true,
	authWidth:true,

	title:"问卷调查问题配置信息",
	loadMask:true,
	dockedItems:[{
		dock:'top',
		xtype:'toolbar',	
		items:['->',{
			text:'新增',
			iconCls:'Add',
			xtype:'button',
			handler:function(){
				newWindow(null);
			}
		},'-',{
			text:'删除',
			iconCls:'Decline',
			xtype:'button',
			handler:otherDelete
		}]		
	},{
		dock:'bottom',
		xtype:'label',
		html:'<div style="font-size:12px;color:red">1.双击可进行单行编辑</div>'
	}],
	listeners:
    {
        'itemdblclick': function(dataview, record, item, index, e) {
        	newWindow(record);
        	}    //单击击事件
        }
});
function newWindow(record){
	var editInquire = Ext.create('Ext.Window',{
		id:'editInquireId',
		layout:'form',
		width:400,
		height:200,
		//closeAction:'hide',
		plain:true,
		resizable : false,
		title:'问卷调查问题信息',
		items:[{
			xtype:'textfield',
			fieldLabel:'问题编号',
			id:'inquireCode',
			name:'inquireCode',
			hidden:true,
			listeners: {
	               'afterrender': function () {
	            	   //Ext.Msg.alert("ss",record);
	                   if (record!=null){
	                	   this.setValue(record.get('inquireCode'));
	                   }
	               }
	           }
		},{
				   xtype:'textfield',  
		           fieldLabel:'问题', 
		           id:'inquireTitle',
		           name:'inquireTitle',
		           //readOnly:true,
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('inquireTitle'));
		                   }
		               }
		           }
			},{
				   xtype:'textfield',  
		           fieldLabel:'答案A', 
		           id:'inquireA',
		           name:'inquireA',  
		          // readOnly:true,
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('inquireA'));
		                   }
		               }
		           }
			},{
				   xtype:'textfield',  
		           fieldLabel:'答案B', 
		           id:'inquireB',
		           name:'inquireB',  
		           allowBlank:false,  
		           blankText:'不能为空',
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('inquireB'));
		                   }
		               }
		           }
			},{
				   xtype:'textfield',  
		           fieldLabel:'答案C', 
		           id:'inquireC',
		           name:'inquireC',  
		           allowBlank:false,  
		           blankText:'不能为空',
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('inquireC'));
		                   }
		               }
		           }
			},{
				   xtype:'textfield',  
		           fieldLabel:'答案D', 
		           id:'inquireD',
		           name:'inquireD',  
		           allowBlank:false,  
		           blankText:'不能为空',
		           listeners: {
		               'afterrender': function () {
		            	   //Ext.Msg.alert("ss",record);
		                   if (record!=null){
		                	   this.setValue(record.get('inquireD'));
		                   }
		               }
		           }
			}],
		buttons : [ {
			xtype : "button",
			text : "确定",
			pressed : false,
			handler : validatorData
		},
		{
			xtype : "button",
			text : "重置",
			handler : function() {
				Ext.getCmp('inquireTitle').setValue('');
				Ext.getCmp('inquireA').setValue('');
				Ext.getCmp('inquireB').setValue('');
				Ext.getCmp('inquireC').setValue('');
				Ext.getCmp('inquireD').setValue('');
		}
		}],
	buttonAlign : "center",
	plain:true
		
	});
	editInquire.show();
}
function validatorData(){ 
	var inquireCode=Ext.getCmp('inquireCode').value;
	var inquireTitle = Ext.getCmp('inquireTitle').value;
	if(inquireTitle == "" || inquireTitle == null){
		Ext.Msg.alert("提示","题目不能为空");
		return;
	}
	var inquireA = Ext.getCmp('inquireA').value;
	if(inquireA == null || inquireA == ""){
		Ext.Msg.alert("提示","A不能为空");
		return;
	}
	var inquireB = Ext.getCmp('inquireB').value;
	if(inquireB == null || inquireB == ""){
		Ext.Msg.alert("提示","B不能为空");
		return;
	}
	var inquireC = Ext.getCmp('inquireC').value;
	if(inquireC == null || inquireC == ""){
		Ext.Msg.alert("提示","C不能为空");
		return;
	}
	var inquireD = Ext.getCmp('inquireD').value;
	if(inquireD == null || inquireD == ""){
		Ext.Msg.alert("提示","D不能为空");
		return;
	}
	var url="addInquireAction.action";
	if(inquireCode != null && inquireCode != ""){
		url = "updateInquireAction.action";
	}
	var jsonString="{'inquireCode':"+"'"+inquireCode+"'"
	+",'inquireTitle':"+"'"+inquireTitle+"'"
	+",'inquireA':"+"'"+inquireA+"'"
	+",'inquireB':"+"'"+inquireB+"'"
	+",'inquireC':"+"'"+inquireC+"'"
	+",'inquireD':"+"'"+inquireD+"'"
	+"}";
	Ext.Ajax.request({  
        url : url,  
        params : {  
        	jsonString : jsonString
        },  
        method : 'POST',  
        success : function(response, opts) {  
            var obj = Ext.decode(response.responseText);  
            // 当后台数据同步成功时  
            if (obj.success) {  
            	Ext.getCmp('editInquireId').close();
            	inquirestore.load();
            	Ext.Msg.alert("提示","操作成功");
            } else {  
            	Ext.Msg.alert("提示",obj.msg);
            }  
        }  
    });  
}
function otherDelete() {  
    var data = grid.getSelectionModel().getSelection();  
    if (data.length == 0) {  
        Ext.Msg.alert("提示","请先选择要操作的行");  
        return;  
    } else {  
        Ext.Msg.confirm("请确认", "是否真的要删除数据？", function(button, text) {  
            if (button == "yes") {  
                var inquireIds = [];  
                Ext.Array.each(data, function(record) {  
                            var inquireId=record.get('publicId');  
                            inquireIds.push(inquireId);  
                        });
                Ext.Ajax.request({  
                    url : 'deleteSystemParamAction.action',  
                    params : {  
                    	dels : inquireIds.join(',') 
                    },  
                    method : 'POST',  
                    success : function(response, opts) {  
                        var obj = Ext.decode(response.responseText);  
                        // 当后台数据同步成功时  
                        if (obj.success) {  
                        	systemParamstore.load();
                        	Ext.Msg.alert("提示","删除成功");
                        } else {  
                        	Ext.Msg.alert("提示",obj.msg);
                        }  
                    }  
                });  
            }  
        });  
    }  
}  

return grid;
};
